package xin.nick.demo;

import org.apache.poi.xssf.usermodel.XSSFRow;

import java.io.*;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class Import2MySQL {

    public static void main(String[] args) throws  IOException {

        // 准备连接

        HashMap<String,String> map4 = ProcessExcel.load2Excel("E:\\Temp\\22\\83.xlsx");


        ArrayList<String[]> exportList = new ArrayList<String[]>();

        for(String key : map4.keySet()) {
            String value = map4.get(key);
            if(value != null && key != null) {
                String[] ss = new String[2];
                ss[0] = key;
                ss[1] = value;
                exportList.add(ss);
            }
        }

        ArrayList<String> list = appendSql(exportList);


        File outFile = new File("E:\\Temp\\22\\84.sql");
        if (!outFile.exists()) {
            outFile.createNewFile();
        }
        BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(outFile));

        for(String s : list) {
            bufferedWriter.write(s);
        }
        bufferedWriter.flush();
        bufferedWriter.close();
        System.out.println("OK;l;;");
    }

    public static ArrayList<String> appendSql(ArrayList<String[]> exportList) {
        ArrayList<String> list = new ArrayList<>();

        int len = exportList.size();
        for(int i = 0; i < len; i++) {
            String[] ss = exportList.get(i);


            String sqlLine =
                    "('"+ IDFactory.newGUID() +"', " +
                    "'" +ss[0]+ "', " +
                    "'" +ss[1]+ "', " ;

            list.add(sqlLine);

        }

        return list;
    }

}
